<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>formatSeconds</title>
</head>

<body>
    <script>
        const formatSeconds = s => {
            const [hour, minute, second, sign] =
                s > 0
                    ? [s / 3600, (s / 60) % 60, s % 60, '']
                    : [-s / 3600, (-s / 60) % 60, -s % 60, '-'];
            return (
                sign +
                [hour, minute, second]
                    .map(v => `${Math.floor(v)}`.padStart(2, '0'))
                    .join(':')
            );
        };
        document.writeln(formatSeconds(99999))
    </script>
</body>

</html>